home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 395_01 / avl / slintrnl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-04  |  1.2 KB  |  47 lines

  1. /* internal header file for implementations of sortlist
  2.    functions */
  3.  
  4. #if !defined(SLINTRNL_H)
  5. #define SLINTRNL_H
  6.  
  7. #include "align.h"
  8.  
  9. /* the beginning part of a node in the AVL tree.  after this
  10.    structure comes the element that is associated with the
  11.    node. */
  12. typedef struct
  13.   {
  14.     /* balance factor */
  15.     char balance;
  16.     /* pointer to each branch */
  17.     void *(branch[2]);
  18.   }
  19. NODE_PREFIX;
  20.  
  21. #define N_UNITS_IN_NODE_PREFIX N_ALIGN_UNITS(sizeof(NODE_PREFIX))
  22.  
  23. /* return address of element within a tree node */
  24. #define ELEM_IN_NODE(NODE) \
  25.   ((void *) (((ALIGN_TYPE *) (NODE)) + N_UNITS_IN_NODE_PREFIX))
  26.  
  27. /* macro to cast a void pointer to a pointer to node prefix */
  28. #define NODE(VP) ((NODE_PREFIX *) (VP))
  29.  
  30. /* indeces into branch array in NODE_PREFIX for the two branches */
  31. #define LESS_BRANCH 0
  32. #define GREATER_BRANCH 1
  33.  
  34. /* macro returning the other branch.  that is, it returns LESS_BRANCH
  35.    for input of GREATER_BRANCH and vis-versa */
  36. #define OTHER(THIS) (1 - (THIS))
  37.  
  38. /* balance an unbalanced tree.  returns non-zero if depth
  39.    of tree reduced by 1, otherwise 0. */
  40. int balance_tree
  41.   (
  42.     /* pointer to pointer to subtree of sorted list to balance */
  43.     void **t
  44.   );
  45.  
  46. #endif
  47.